<template>
  <base-echarts :isLoading="isLoading" :option="options" :height="height" :width="width" :clear="true"></base-echarts>
</template>

<script type="text/ecmascript-6">
  import BaseEcharts from '../base/BaseEcharts';
  import {formatDate} from '@/utils/dateFormat';

  export default {
    name: 'lineAndZoom',
    components: {BaseEcharts},
    props: ['datas', 'width', 'height', 'isLoading'],
    data() {
      return {};
    },
    methods: {},
    computed: {
      options() {
        return {
          grid: {
            left: '3%',
            right: '4%',
            containLabel: true,
          },
          xAxis: [
            {
              type: 'category',
              min: this.datas.startTime,
              splitLine: {
                show: false,
              },
              boundaryGap: false,
              // axisLabel: {
              //   show: true,
              //   formatter: timeValue => {
              //     return formatDate(timeValue, "yyyy-MM-dd hh:mm:ss")
              //   },
              // },
            }
          ],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
            },
          },
          yAxis: [
            {
              name: '单位(%)',
              splitLine: {
                show: true,
              },
            },
            {
              name: '单位(Byte)',
              splitLine: {
                show: true,
              },
            },
          ],
          action: {
            dataZoom: {
              show: true,
            },
          },
          dataZoom: {
            start: 97,
            end: 100,
            type: 'slider',
          },
          legend: {
            data: ['CPU使用率', '内存使用率', '网络发送字节', '网络接收字节'],
          },
          series: [
            {
              name: 'CPU使用率',
              smooth: true,
              type: 'line',
              data: this.datas.cpu,
              animation: false,
              showSymbol: false,
            },
            {
              name: '内存使用率',
              smooth: true,
              type: 'line',
              data: this.datas.memory,
              animation: false,
              showSymbol: false,
            },
            {
              name: '网络发送字节',
              smooth: true,
              type: 'line',
              data: this.datas.networkIn,
              animation: false,
              showSymbol: false,
              yAxisIndex: 1,
            },
            {
              name: '网络接收字节',
              smooth: true,
              type: 'line',
              data: this.datas.networkOut,
              animation: false,
              showSymbol: false,
              yAxisIndex: 1,
            },
          ],

        }
      }
    }
  }
</script>
